package com.nic.view.util.contactList;


import android.text.TextUtils;

import java.util.Comparator;

/**
 * Created by Administrator on 2018/11/5.
 */

public abstract class PinYinSortBean implements Comparator<PinYinSortBean> {
    private boolean isShowTitle;

    public boolean isShowTitle() {
        return isShowTitle;
    }

    public void setShowTitle(boolean showTitle) {
        isShowTitle = showTitle;
    }

    private String pinyin;
    private String firstLetter;

    public String getPinyin() {
        if (TextUtils.isEmpty(pinyin)) {
            pinyin = PinYinUtils.getPinyin(sortName());
            return pinyin;
        }
        // 根据名称获取拼音
        return pinyin;
    }

    /**
     * 要排序的名称
     *
     * @return
     */
    public abstract String sortName();

    /**
     * 拼音的首字母
     *
     * @return
     */
    public String getFirstLetter() {
//        返回首字母，大写
        if (TextUtils.isEmpty(firstLetter)) {
            firstLetter = PinYinUtils.getFirstLetter(sortName());
            return firstLetter;
        }
        return firstLetter;
    }

    public void setFirstLetter(String firstLetter) {
        this.firstLetter = firstLetter;
    }

    @Override
    public int compare(PinYinSortBean o1, PinYinSortBean o2) {
        if (o1.getFirstLetter().equals("#") && !o2.getFirstLetter().equals("#")) {
            return 1;
        } else if (!o1.getFirstLetter().equals("#") && o2.getFirstLetter().equals("#")) {
            return -1;
        } else {
            return o1.getPinyin().compareToIgnoreCase(o2.getPinyin());
        }

    }
}
